package com.ruoyi.web.controller.system;

import java.util.List;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.system.domain.SysVip;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;

import com.ruoyi.system.service.ISysVipService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 会员管理Controller
 * 
 * @author ruoyi
 * @date 2025-08-09
 */
@RestController
@RequestMapping("/system/vip")
public class SysVipController extends BaseController
{
    @Autowired
    private ISysVipService sysVipService;

    /**
     * 查询会员管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:vip:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysVip sysVip)
    {
        startPage();
        LoginUser loginUser = getLoginUser();
        SysUser user = loginUser.getUser();
        sysVip.setDeptId(user.getDeptId());
        List<SysVip> list = sysVipService.selectSysVipList(sysVip);
        return getDataTable(list);
    }

    /**
     * 导出会员管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:vip:export')")
    @Log(title = "会员管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysVip sysVip)
    {
        List<SysVip> list = sysVipService.selectSysVipList(sysVip);
        ExcelUtil<SysVip> util = new ExcelUtil<SysVip>(SysVip.class);
        util.exportExcel(response, list, "会员管理数据");
    }

    /**
     * 获取会员管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:vip:query')")
    @GetMapping(value = "/{vipId}")
    public AjaxResult getInfo(@PathVariable("vipId") Long vipId)
    {
        return success(sysVipService.selectSysVipByVipId(vipId));
    }

    /**
     * 新增会员管理
     */
    @PreAuthorize("@ss.hasPermi('system:vip:add')")
    @Log(title = "会员管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysVip sysVip)
    {
        LoginUser loginUser = getLoginUser();
        SysUser user = loginUser.getUser();
        sysVip.setDeptId(user.getDeptId());
        return toAjax(sysVipService.insertSysVip(sysVip));
    }

    /**
     * 修改会员管理
     */
    @PreAuthorize("@ss.hasPermi('system:vip:edit')")
    @Log(title = "会员管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysVip sysVip)
    {
        return toAjax(sysVipService.updateSysVip(sysVip));
    }

    /**
     * 删除会员管理
     */
    @PreAuthorize("@ss.hasPermi('system:vip:remove')")
    @Log(title = "会员管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{vipIds}")
    public AjaxResult remove(@PathVariable Long[] vipIds)
    {
        return toAjax(sysVipService.deleteSysVipByVipIds(vipIds));
    }
}
